<template>
	<view class="my-container">
		<view class="my-header">
			<view class="item c-theme-btn-w" style="margin-right: 20rpx;">
				<image src="../../static/imgs/my-message.png" mode=""></image>
			</view>
			<view class="item c-theme-btn-w">
				<image src="../../static/imgs/my-sao.png" mode="" style="height: 25rpx;width: 27rpx;"></image>
			</view>
		</view>
		<navigator class="my-user" url="./myCenter">
			<view class="left c-theme-btn-b"></view>
			<view class="user-info">
				<view class="user-name">
					{{userInfo.username}}
				</view>
				<view class="desc">
					{{userInfo.intro?userInfo.intro:'这个人很懒什么都没有留下'}}
				</view>
			</view>
		</navigator>
		<view class="my-box">
			<view class="box-item c-theme-btn-w">
				<view class="left">
					<image src="../../static/imgs/my-collet.png" mode=""></image>
				</view>
				<view class="right">
					<view class="num">
						<text>{{collectNum?collectNum:'0'}}</text>
					</view>
					<navigator class="name" url="./collect">
						<text>我的收藏</text>
					</navigator>
				</view>
			</view>
			<view class="box-item c-theme-btn-w">
				<view class="left">
					<image src="../../static/imgs/my-order.png" mode=""></image>
				</view>
				<view class="right">
					<view class="num">
						<text>{{buyNum}}</text>
					</view>
					<navigator class="name" url="./order">
						<text>我的订单</text>
					</navigator>
				</view>
			</view>
			<view class="box-item c-theme-btn-w">
				<view class="left">
					<image src="../../static/imgs/my-coupon.png" mode=""></image>
				</view>
				<view class="right">
					<view class="num">
						<text>4</text>
					</view>
					<navigator class="name" url="./coupon">
						<text>我的优惠卷</text>
					</navigator>
				</view>
			</view>
		</view>
		<view class="my-setting">
			<navigator class="item c-theme-btn-w" url="./SafetyCenter">
				<view class="left">
					<image src="../../static/imgs/my-safa.png" mode=""></image>
					<view class="title">
						账号安全中心
					</view>
				</view>
				<view class="right">
					<image src="../../static/imgs/right.png" mode=""></image>
				</view>
			</navigator>
			<view class="item c-theme-btn-w">
				<view class="left">
					<image src="../../static/imgs/my-helep.png" mode=""></image>
					<view class="title">
						帮助与反馈
					</view>
				</view>
				<view class="right">
					<image src="../../static/imgs/right.png" mode=""></image>
				</view>
			</view>
		</view>
		<view class="login-out c-theme-btn-w" @click="logoOut">
			<text>退出登录</text>
		</view>
	</view>
</template>

<script>
	import {
		myInfo
	} from "@/api/my.js"
	import {
		collectCourse,
		courseBuy
	} from "@/api/course.js"
	export default {
		data() {
			return {
				userInfo: {},
				collectNum: "",
				buyNum: ""
			};
		},
		computed: {
			userId() {
				return uni.getStorageSync("userInfo").id
			}
		},
		methods: {
			getMyInfo() {
				myInfo(this.userId).then(res => {
					this.userInfo = res.data
				})
			},
			// 获取搜藏列表数据
			getCourseList() {
				collectCourse().then(res => {
					if (res.data) this.collectNum = res.data.length
				})
			},
			getCourseBuyList() {
				courseBuy().then(res => {
					if (res.data) this.buyNum = res.data.length
				})
			},
			logoOut() {
				uni.removeStorageSync("token")
				uni.navigateTo({
					url: "/pages/Login/Login"
				})
			}
		},
		onShow() {
			this.getMyInfo()
			this.getCourseList()
			this.getCourseBuyList()
		}
	}
</script>

<style lang="scss" scoped>
	.my-container {
		padding: 60rpx;

		.my-header {
			display: flex;
			justify-content: flex-end;
			align-items: center;

			.item {
				width: 61rpx;
				height: 61rpx;
				background-color: #FFFFFF;
				border-radius: 41rpx 41rpx 41rpx 41rpx;
				line-height: 61rpx;
				text-align: center;

				image {
					width: 36rpx;
					height: 36rpx;
					margin-top: 15rpx;
				}
			}
		}

		.my-user {
			display: flex;
			align-items: center;

			.left {
				width: 123rpx;
				border-radius: 50%;
				background: #3F7BED;
				height: 123rpx;
				margin-right: 20rpx;
			}

			.user-info {
				.user-name {
					font-size: 37rpx;
				}

				.desc {
					font-size: 29rpx;
					color: #3D5464;
				}
			}

		}

		.my-box {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin: 60rpx 0;

			.box-item {
				height: 71rpx;
				padding: 25rpx;
				display: flex;
				align-items: center;
				border: 2px solid #FFFFFF;
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				background: #F4F6F8;

				.left {
					image {
						width: 34rpx;
						height: 32rpx;
					}
				}

				.right {
					margin-left: 20rpx;

					.num {

						color: #FFB300;
						font-size: 35rpx;
					}

					.name {
						font-size: 20rpx;
						color: #3D5464;
					}
				}
			}
		}

		.my-setting {
			margin: 40rpx 0;

			.item {
				padding: 28rpx;
				background: #F4F6F8;
				display: flex;
				align-items: center;
				justify-content: space-between;
				border: 2rpx solid #FFFFFF;
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				margin: 40rpx 0;

				.left {
					display: flex;
					align-items: center;

					image {
						width: 45rpx;
						height: 47rpx;
						margin-right: 20rpx;
					}

					.title {
						font-size: 22rpx;
					}
				}

				.right {
					image {
						width: 17rpx;
						height: 17rpx;
					}
				}
			}
		}

		.login-out {
			line-height: 80rpx;
			text-align: center;
			border-radius: 41rpx 41rpx 41rpx 41rpx;
			background: #FFFFFF;
			height: 80rpx;
			margin: 0 60rpx;
			font-size: 22rpx;
			color: #999FAD;
		}
	}
</style>
